package com.wzf.springdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wzf.springdemo.bean.BusDevice;
import com.wzf.springdemo.bean.ResultMessage;
import com.wzf.springdemo.constant.Constants;
import com.wzf.springdemo.service.BusDeviceService;
import com.wzf.springdemo.utils.AjaxResult;
import com.wzf.springdemo.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wzf")
@Api(tags="共同业务")
public class BusDeviceController {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private BusDeviceService bs;

    @GetMapping("/demo")
    @ApiOperation(value ="getb")
    public ResultMessage<Object> getb(String st){
        LambdaQueryWrapper<BusDevice> queryWrapper = new LambdaQueryWrapper<BusDevice>();
        queryWrapper.like(BusDevice::getName,"1").lt(BusDevice::getIsdeleted,0);
        List<Map<String, Object>> maps = bs.listMaps(queryWrapper);
        return ResultUtil.data(maps);
    }

    @GetMapping("/getOnly")
    public AjaxResult getOnly(String data){
        JSONObject resMain = new JSONObject();
        JSONObject resPart1 = new JSONObject();
        try {
            resMain =  bs.getOnly(data);
        } catch (Exception e) {
            resPart1.put(Constants.RESULT_JSON_PART1_RESULT, Constants.SERVER_ERR_RESULT);
            resPart1.put(Constants.RESULT_JSON_PART1_ERRMSG, Constants.SERVER_ERR_MESSAGE);
            resMain.put(Constants.RESULT_JSON_PART1_NAME, resPart1);
            logger.error(Constants.SERVER_ERR_MESSAGE,e);
        }

        return AjaxResult.proSuccess(resMain);
    }
}
